package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.dto.ShoppingCartSubDTO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import com.sky.vo.ShoppingCartVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "购物车的接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService cartService;

    /**
     * 添加购物车
     * */
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result<Void> addCart(@RequestBody ShoppingCartDTO dto){
        cartService.addCart(dto);
        return Result.success();
    }

    /**
     * 获取我的购物车列表
     * */
    @ApiOperation("获取我的购物车列表")
    @GetMapping("/list")
    public Result<List<ShoppingCartVO>> list(){
        List<ShoppingCartVO> list = cartService.list();
        return Result.success(list);
    }

    /**
     * 清空我的购物车
     * */
    @ApiOperation("清空我的购物车")
    @DeleteMapping("/clean")
    public Result clean(){
        cartService.clean();
        return Result.success();
    }

    /**
     * 减少购物车数量
     * */
    @ApiOperation("减少购物车数量")
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartSubDTO dto){
        cartService.sub(dto);
        return Result.success();
    }

}
